package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Ziliao;
import com.ruoyi.system.service.IZiliaoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资料上传Controller
 *
 * @author ruoyi
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/system/ziliao")
public class ZiliaoController extends BaseController
{
    @Autowired
    private IZiliaoService ziliaoService;

    /**
     * 查询资料上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:list')")
    @GetMapping("/list")
    public TableDataInfo list(Ziliao ziliao)
    {
        startPage();
        List<Ziliao> list = ziliaoService.selectZiliaoList(ziliao);
        return getDataTable(list);
    }

    /**
     * 导出资料上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:export')")
    @Log(title = "资料上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ziliao ziliao)
    {
        List<Ziliao> list = ziliaoService.selectZiliaoList(ziliao);
        ExcelUtil<Ziliao> util = new ExcelUtil<Ziliao>(Ziliao.class);
        util.exportExcel(response, list, "资料上传数据");
    }

    /**
     * 获取资料上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(ziliaoService.selectZiliaoByFileId(fileId));
    }

    /**
     * 新增资料上传
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:add')")
    @Log(title = "资料上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ziliao ziliao)
    {
        ziliao.setName(SecurityUtils.getLoginUser().getUsername());
        return toAjax(ziliaoService.insertZiliao(ziliao));
    }

    /**
     * 修改资料上传
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:edit')")
    @Log(title = "资料上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ziliao ziliao)
    {
        return toAjax(ziliaoService.updateZiliao(ziliao));
    }

    /**
     * 删除资料上传
     */
    @PreAuthorize("@ss.hasPermi('system:ziliao:remove')")
    @Log(title = "资料上传", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(ziliaoService.deleteZiliaoByFileIds(fileIds));
    }
}
